//
//  NSAttributedString+YCTools.m
//  Pods
//
//  Created by Apple on 2023/8/5.
//

#import "NSAttributedString+YCTools.h"

@implementation NSAttributedString (YCTools)

+ (NSAttributedString *)attributedStringWithLabel:(NSString *)label labelFont:(UIFont *)labelFont labelColor:(UIColor *)labelColor value:(NSString *)value valueFont:(UIFont *)valueFont valueColor:(UIColor *)valueColor {
    NSDictionary<NSAttributedStringKey, id> *prefixAttr = @{
        NSFontAttributeName:labelFont,
        NSForegroundColorAttributeName:labelColor,
    };
    NSDictionary<NSAttributedStringKey, id> *valueAttr = @{
        NSFontAttributeName:valueFont,
        NSForegroundColorAttributeName:valueColor,
    };
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
    [attrString appendAttributedString:[[NSAttributedString alloc] initWithString:label attributes:prefixAttr]];
    [attrString appendAttributedString:[[NSAttributedString alloc] initWithString:value attributes:valueAttr]];
    return attrString;
}

+ (NSAttributedString *)attributedWithString:(NSString *)text font:(UIFont *)font lineSpacing:(CGFloat)lineSpacing {
    if (!text) {
        return nil;
    }
    
    NSMutableAttributedString *astring = [[NSMutableAttributedString alloc] initWithString:text];
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.lineSpacing = lineSpacing;
    
    NSRange range = NSMakeRange(0, text.length);
    [astring addAttribute:NSParagraphStyleAttributeName value:style range:range];
    [astring addAttribute:NSFontAttributeName value:font range:range];
    
    return astring;
}

@end
